/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} p
 * @param {TreeNode} q
 * @return {boolean}
 */
// 比较两颗二叉树相等：相比较根节点，然后比较左子树，右子树
// 用BFS怎么做？
var isSameTree = function(p, q) {
    const compare = (t1, t2) => {
        if(t1 == null && t2 !== null) return false
        if(t2 == null && t1 !== null) return false
        if(t1.val == t2.val) {
            return compare(t1.left, t2.left) && compare(t1.right, t2.right)
        }
        return false
    }
    return compare(p, q)
};